const puppeteer = require("puppeteer");

async function search(url) {
    const browser = await puppeteer.launch(

    );
    const page = await browser.newPage();
    await page.goto(url, {
        waitUntil: 'networkidle2'
    })
    await page.waitFor(1000)
    await page.hover("body")
    let res = await page.evaluate(() => {
        var $ = window.jQuery;
        var items = $(".search-content .woo");
        var links = [];
        if (items.length > 0) {
            items.each((index,item) => {
                var img=$(item).find(".j a img").attr("src");
                var title=$(item).find(".wooscr .g").text();
                var like=$(item).find(".wooscr .d2 span").text();
                var collect=$(item).find(".wooscr .d .d1 span").text()
                links.push({
                    img,
                    title,
                    like,
                    collect,
                })
            })
        }
        return links
    })
    browser.close();
    return res;
}
module.exports = search;